import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    city: '茂名',
    login: false,
    member: false,
    addressL: {
      flag: false,
      name: '',
      sex: '',
      number: '',
      address: '',
      door: ''
    },
    newLogin: false
  },
  actions: {
    changeCity (ctx, city) {
      ctx.commit('changeData', city)
    },
    changeLogin (ctx, login) {
      ctx.commit('loginFlag', login)
    },
    changeMember (ctx, member) {
      ctx.commit('memberFlag', member)
    },
    changeAddress (ctx, address) {
      ctx.commit('changeAdd', address)
    },
    changeNewLogin (ctx, newLogin) {
      ctx.commit('changeNewLogin', newLogin)
    }
  },
  mutations: {
    changeData (state, city) {
      state.city = city
    },
    loginFlag (state, login) {
      state.login = login
    },
    memberFlag (state, member) {
      state.member = member
    },
    changeAdd (state, address) {
      state.addressL.flag = address.flag
      state.addressL.name = address.name
      state.addressL.sex = address.sex
      state.addressL.address = address.address
      state.addressL.number = address.number
      state.addressL.door = address.door
    },
    changeNewLogin (state, newLogin) {
      state.newLogin = newLogin
    }
  }
})
